home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
TPUG - Toronto PET Users Group
/
TPUG Users Group CD
/
TPUG Users Group CD.iso
/
AMIGA
/
AMICUS
/
AMICUS04.ADF
/
C
/
diskio.c
< prev
next >
Wrap
C/C++ Source or Header
|
1985-10-30
|
6KB
|
172 lines
/* diskio.c with sun makefile v1.0 *
/****************************************************************
* *
* Copyright 1985, Commodore Amiga Inc. All rights reserved. *
* No part of this program may be reproduced, transmitted, *
* transcribed, stored in retrieval system, or translated into *
* any language or computer language, in any form or by any *
* means, electronic, mechanical, magnetic, optical, chemical, *
* manual or otherwise, without the prior written permission of *
* Commodore Amiga Incorporated, 983 University Ave, #D *
* Los Gatos, CA 95030 *
* *
****************************************************************/
/*** Makefile ***************************/
all: diskio.ld
SUBSYSNAME= diskio
AFILES= diskio.asm
CFILES= diskio.c
OFILES= diskio.obj
MYLIBS= ${LIBDIR}/debug.lib
MAKEFILE= Makefile
SUBSYSGROUP=
EXTERNIFILES=
IFILES= ${EXTERNIFILES}
EXTERNHFILES= intuall.h
HFILES= global.h ${EXTERNHFILES}
LFLAGS= map=$*.lmap xref=$*.xref
STARTUP= $(VERDIR)/$(TERNAL)/lib/startup.obj
CFLAGS= -DDEBUG
.INCLUDE=/usr/commodore/amiga/V1/tools/makemeta
/*** diskio.c ***************************/
#include <exec/types.h>
#include <exec/io.h>
#include <devices/trackdisk.h>
#define TD_READ CMD_READ
#define BLOCKSIZE TD_SECTOR
SHORT error;
struct Port *diskport;
struct IOStdReq *diskreq;
BYTE diskbuffer[BLOCKSIZE];
BYTE *diskdata;
SHORT testval;
extern struct Port *CreatePort();
extern struct IOStdReq *CreateStdIO();
ReadCylSec(cyl, sec, hd)
SHORT cyl, sec, hd;
{
LONG offset;
diskreq->io_Length = BLOCKSIZE;
diskreq->io_Data = diskbuffer;
/* show where to put the data when read */
diskreq->io_Command = TD_READ;
/* convert from cylinder, head, sector to byte-offset value to get
* right one (as dos and everyone else sees it)...*/
/* driver reads one CYLINDER at a time (head does not move for
* 22 sequential sector reads, or better-put, head doesnt move for
* 2 sequential full track reads.)
*/
offset = TD_SECTOR * (sec + NUMSECS * hd + NUMSECS * NUMHEADS * cyl);
diskreq->io_Offset = offset;
DoIO(diskreq);
return;
}
MotorOn()
{
/* TURN ON DISK MOTOR ... old motor state is returned in io_Actual */
diskreq->io_Length = 1; /* this says motor is to be turned on */
diskreq->io_Command = TD_MOTOR; /* do something with the motor */
DoIO(diskreq);
printf("\nOld motor state was: %ld",diskreq->io_Actual);
printf("\nio_Error value was: %ld",diskreq->io_Error);
return;
}
MotorOff()
{
printf("\n\nNow turn it off");
diskreq->io_Length = 0; /* says that motor is to be turned on */
diskreq->io_Command = TD_MOTOR; /* do something with the motor */
DoIO(diskreq);
printf("\nOld motor state was: %ld",diskreq->io_Actual);
printf("\nio_Error value was: %ld",diskreq->io_Error);
return;
}
SeekFullRange(howmany)
SHORT howmany;
{
SHORT i;
for(i=0; i<howmany; i++)
{
diskreq->io_Offset = ((NUMCYLS -1)*NUMSECS*NUMHEADS -1 ) * 512;
/* seek to cylinder 79, head 1 */
diskreq->io_Command = TD_SEEK;
DoIO(diskreq);
if(diskreq->io_Error != 0)
printf("\nSeek Cycle Number %ld, Error = %ld",
i, diskreq->io_Error);
diskreq->io_Offset = 0;
/* seek to cylinder 0, head 0 */
diskreq->io_Command = TD_SEEK;
DoIO(diskreq);
if(diskreq->io_Error != 0)
printf("\nSeek Cycle Number %ld, Error = %ld",
i, diskreq->io_Error);
printf("\nCompleted a seek");
}
return;
}
main()
{
LONG i,j;
SHORT cylinder,head,sector;
diskdata = &diskbuffer[0];
/* point to first location in disk buffer */
diskport = CreatePort(0,0);
diskreq = CreateStdIO(diskport);
/* make an io request block for communicating with the disk */
for(j=0; j<2; j++)
{ /* do both drives 0 and 1 */
error = OpenDevice(TD_NAME,j,diskreq,0);
/* open the device for access, unit 0 is builtin drive */
printf("\nError value returned by OpenDevice was: %lx", error);
MotorOn();
SeekFullRange(10);
for(cylinder=0; cylinder<80; cylinder++) /* tracks to test */
{
for(head=0; head<2; head++) /* number of heads to test */
for(sector=0; sector<11; sector++) /* sectors to test */
{
ReadCylSec(cylinder, sector, head);
if(diskreq->io_Error != 0)
printf("\nError At Cyl=%ld, Sc=%ld, Hd=%ld, Error=%ld",
cylinder,sector,head,diskreq->io_Error);
}
printf("\nCompleted reading Cylinder=%ld",cylinder);
}
MotorOff();
CloseDevice(diskreq);
} /* end of for-loop testing second drive */
DeleteStdIO(diskreq);
DeletePort(diskport);
} /* end of main */